package vn.com.bookstore.model;

import java.util.ArrayList;

import com.google.gson.Gson;

import vn.com.bookstore.ObjectStore;

// Book Class
@SuppressWarnings("serial")
public class Book extends ObjectStore {
	public static final String TAG = "book";

	public static final int TYPE_THEORY = 0;
	public static final int TYPE_COMICS = 1;
	
	public int id = -1;
	public int storeId = -1;
	public String title = "";
	public String image = "";
	public String author = "";
	public int type = TYPE_THEORY;
	public ArrayList<Page> pages = new ArrayList<Page>();

	public Book() {

	}

	public static Book createDataSample() {
		return createDataSample(1);
	}

	public static Book createDataSample(int index) {
		Book book = new Book();
		book.id = index;
		book.title = "book " + index;
		book.author = "author " + index;
		book.pages = new ArrayList<Page>();
		book.image = "";
		for (int i = 0; i < 15; i++) {
			Page page = Page.createDataSample(i);
			book.pages.add(page);
		}
		return book;
	}
	
	public boolean isComics(){
		if(type == TYPE_COMICS) return true;
		return false;
	}

	public static Book parseGson(String json) {
		try {
			Gson gson = new Gson();
			Book book = (Book) gson.fromJson(json, Book.class);
			return book;
		} catch (Exception e) {
			return null;
		}
	}
}
